//package com.example.springboot.mapping;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.core.annotation.AnnotationUtils;
//import org.springframework.stereotype.Component;
//import org.springframework.util.ObjectUtils;
//import org.springframework.util.ReflectionUtils;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.method.HandlerMethod;
//import org.springframework.web.servlet.mvc.condition.RequestCondition;
//import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
//import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import java.lang.reflect.Method;
//import java.util.Arrays;
//import java.util.Set;
//
///**
// * @author by Mr. Li 2021/1/29 23:14
// */
//@Slf4j
//public class VersionRequestHandlerMapping extends RequestMappingHandlerMapping {
//
//    /**
//     * 是否为房钱的handler处理
//     *
//     * @param beanType beanType
//     * @return 布尔
//     */
//    @Override
//    protected boolean isHandler(Class<?> beanType) {
//        // 获取该指定方法的所有方法
//        final Method[] methods = ReflectionUtils.getAllDeclaredMethods(beanType);
//        for (Method method : methods) {
//            // 判断方法是都使用了该注解
//            if (!ObjectUtils.isEmpty(AnnotationUtils.findAnnotation(method, VersionRequestMapping.class))) {
//                log.debug(">>>>>>>>>[custom mapping matching ，match method ：{},supports @VersionRequestMapping]", method);
//                return true;
//            }
//        }
//        return false;
//    }
//
//    /**
//     * 匹配映射
//     *
//     * @param info       info
//     * @param lookupPath 映射路径
//     * @param request    请求
//     */
//    @Override
//    protected void handleMatch(RequestMappingInfo info, String lookupPath, HttpServletRequest request) {
//        log.debug(">>>>>>>>>>>>>>>>>>> custom mapping is match");
//        request.setAttribute("version", request.getRequestURI().split("/")[1]);
//    }
//
//    @Override
//    protected HandlerMethod handleNoMatch(Set<RequestMappingInfo> infos, String lookupPath, HttpServletRequest request) throws ServletException {
//        log.debug(">>>>>>>>>>>>>>>>>>> custom mapping is not match");
//        return null;
//    }
//
//    /**
//     * 通过method 获取映射
//     *
//     * @param method      方法
//     * @param handlerType class 类型
//     * @return 请求映射信息
//     */
//    @Override
//    protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
//        log.debug(">>>>>>>>>>>>>>>> getMappingForMethod is running ，method：{}", method);
//        RequestMappingInfo info = null;
//        // look for @DumberRequestMapping annotation for the Method method from signature
//        final VersionRequestMapping annotation = AnnotationUtils.findAnnotation(method, VersionRequestMapping.class);
//        if (!ObjectUtils.isEmpty(annotation)) {
//            final RequestCondition<?> customMethodCondition = getCustomMethodCondition(method);
//            info = createRequestMappingInfo((RequestMapping) annotation, customMethodCondition);
//        }
//        return info;
//    }
//
//    /**
//     * 属性设置
//     */
//    @Override
//    public void afterPropertiesSet() {
//        // 提升当前 HandlerMapping 的在映射处理器列表中的顺序
//        super.setOrder(0);
//        super.afterPropertiesSet();
//    }
//}
